﻿Imports system.Data.SqlClient
Public Class SuaKetQua

    Private _maSV As String
    Private _tenSV As String
    Private _p1 As String
    ' Private _monHoc_ID As String
    Private _lanThi As Integer

    Sub New(ByVal MaSV As String, ByVal TenSV As String)
        ' TODO: Complete member initialization 
        _maSV = MaSV
        _tenSV = TenSV
    End Sub

    Sub New(ByVal p1 As String, ByVal MonHoc_ID As String, ByVal LanThi As Integer)
        ' TODO: Complete member initialization 
        _p1 = p1
        _monHoc_ID = MonHoc_ID
        _lanThi = LanThi
    End Sub

    Private Property SinhVien_ID As Object

    Private Property MonHoc_ID As String

    Private Sub btnSua_Click(sender As System.Object, e As System.EventArgs) Handles btnSua.Click
        Dim con As SqlConnection = New SqlConnection()
        con.ConnectionString = Ketnoi.str
        con.Open()
        Dim cmd As SqlCommand = New SqlCommand()
        cmd.Connection = con

        Dim DiemThi As Double
        DiemThi = Convert.ToDouble(txtDiemThi.Text)
        Dim TongKet As Double
        TongKet = Convert.ToDouble(txtDiemTongKet.Text)
        cmd.CommandText = "UPDATE KetQua SET DiemThi=" + DiemThi + ",DiemTongKet=" + TongKet + " WHERE ID_SinhVien='" + SinhVien_ID + "' AND ID_MonHoc='" + MonHoc_ID + "' AND LanThi=" + LanThi + ""
        Dim result As DialogResult
        result = MessageBox.Show("BẠN CÓ MUỐN THAY ĐỔI THÔNG TIN KHÔNG?", "THÔNG BÁO", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
        If result = DialogResult.Yes Then
            cmd.ExecuteNonQuery()
            con.Close()
            MessageBox.Show("CẬP NHẬT THÀNH CÔNG", "THÔNG BÁO")
        End If
        Me.Close()
        Dim frm As New DanhSachKetQua(SinhVien_ID)
        frm.Show()
    End Sub

    Private Sub btnThoat_Click(sender As System.Object, e As System.EventArgs) Handles btnThoat.Click
        Me.Close()
    End Sub

    Private Sub SuaKetQua_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Dim con As SqlConnection = New SqlConnection()
        con.ConnectionString = Ketnoi.str
        con.Open()
        Dim cmd As SqlCommand = New SqlCommand()
        cmd.Connection = con
        cmd.CommandText = "SELECT DiemThi,DiemTongKet FROM KetQua WHERE ID_SinhVien='" + SinhVien_ID + "' AND ID_MonHoc='" + MonHoc_ID + "' AND LanThi=" + LanThi + ""
        Dim rd As SqlDataReader, rd1 As SqlDataReader
        rd = cmd.ExecuteReader()
        Dim td As DataTable = New DataTable()
        td.Load(rd)
        Me.txtDiemThi.Text = td.Rows(0)(0).ToString()
        Me.txtDiemTongKet.Text = td.Rows(0)(1).ToString()
        Me.txtLanThi.Text = LanThi.ToString()
        cmd.CommandText = "SELECT TenMonHoc FROM MonHoc WHERE MonHoc_ID='" + MonHoc_ID + "'"
        rd1 = cmd.ExecuteReader()
        Dim td1 As DataTable = New DataTable()
        td1.Load(rd1)
        Me.txtTenMonHoc.Text = td1.Rows(0)(0).ToString()
        con.Close()
    End Sub

    Private Function LanThi() As Object
        Throw New NotImplementedException
    End Function

End Class